package com.vdm.action;

import com.vdm.model.*;
import com.vdm.service.*;
import com.vdm.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/statistics")
public class StatisticsController {

    @Autowired
    DispatchService dispatchService;

    @Autowired
    SalesmanService salesmanService;

    @Autowired
    CompanyService companyService;

    @Autowired
    VehicleService vehicleService;

    @Autowired
    PilotService pilotService;

    @Autowired
    AmountService amountService;

    @RequestMapping("toSettlementDetails")
    public String toSettlementDetails(){
        return "statistics/settlementDetails";
    }

    @RequestMapping("toTripRateAnalysis")
    public String toTripRateAnalysis(){
        return "statistics/tripRateAnalysis";
    }

    @ResponseBody
    @RequestMapping(value = "/tripRateAnalysis",method = RequestMethod.GET)
    public Map<String,Object> tripRateAnalysis(String startDateSel){
        Map map = new HashMap();

        if(!StringUtil.isEmpty(startDateSel)){
            String[] strs=startDateSel.split(" - ");
            map.put("startDateSelFrom", strs[0]);
            map.put("startDateSelTo", strs[1]);
        }else{
            map.put("startDateSelFrom",null );
            map.put("startDateSelTo",null );
        }
        List<HashMap<String,Object>> list = dispatchService.tripRateAnalysis(map);

        Map<String,Object> retMap = new HashMap();
        retMap.put("code",0);
        retMap.put("msg","");

        retMap.put("data",list);
        return retMap;
    }

    @ResponseBody
    @RequestMapping(value = "/carSubsidize",method = RequestMethod.GET)
    public Map<String,Object> carSubsidize(String startDateSel){
        Map map = new HashMap();
        if(!StringUtil.isEmpty(startDateSel)){
            String[] strs=startDateSel.split(" - ");
            map.put("startDateSelFrom", strs[0]);
            map.put("startDateSelTo", strs[1]);
        }else{
            map.put("startDateSelFrom",null );
            map.put("startDateSelTo",null );
        }

        List<HashMap<String,Object>> list = dispatchService.carSubsidize(map);

        Map<String,Object> retMap = new HashMap();
        retMap.put("code",0);
        retMap.put("msg","");
        retMap.put("data",list);
        return retMap;
    }

    @RequestMapping("toCarSubsidize")
    public String toCarSubsidize(){
        return "statistics/carSubsidize";
    }

    @RequestMapping("/toSingleSettlementDetails")
    public String toSingleSettlementDetails(Model model){
        List<VehicleInfo> vehicleInfos = vehicleService.getAllVehicleInfo();
        model.addAttribute("vehicleInfos",vehicleInfos);
        return "statistics/singleSettlementDetails";
    }

    @RequestMapping("/toReceivedDetails")
    public String toReceivedDetails(Model model){
        //公司信息
        List<CompanyInfo> companyList = companyService.getAllCompanyInfo();
        model.addAttribute("companyList",companyList);
        return "statistics/receivedDetails";
    }
    @RequestMapping("/toUnpaidDetails")
    public String toUnpaidDetails(Model model){
        //公司信息
        List<CompanyInfo> companyList = companyService.getAllCompanyInfo();
        model.addAttribute("companyList",companyList);
        return "statistics/unpaidDetails";
    }

    @RequestMapping("/toDispatchDetails")
    public String toDispatchDetails(Model model){
        //业务员
        List<SalesmanInfo> saleList = salesmanService.getAllSalesmanInfo();
        model.addAttribute("saleList",saleList);

        //公司信息
        List<CompanyInfo> companyList = companyService.getAllCompanyInfo();
        model.addAttribute("companyList",companyList);

        //车辆信息
        List<VehicleInfo> vehicleList = vehicleService.getAllVehicleInfo();
        model.addAttribute("vehicleList",vehicleList);

        //驾驶员信息
        List<PilotInfo> pilotList = pilotService.getAllPilotInfo();
        model.addAttribute("pilotList",pilotList);

        return "statistics/dispatchDetails";
    }


}
